package com.apes.scm.account.account.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.sql.Date;

/**
 * Created by HuJianLin on 2018-01-24.
 * 三级明细账（账面数明细账）
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = DetailOfInventory.CONST_TABLE_NAME)
public class DetailOfInventory {
    public static final String CONST_TABLE_NAME = "acc_detailed_of_inventory";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "三级明细账（账面数明细账）")
    @Comment("内码")
    private Long id; //内码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "enumeration_id", referencedColumnName = "id") //, nullable = false
    @Comment("单据类型编码")
    private Enumeration enumeration; //单据类型编码

    @Column(name = "ORDER_NUMBER", nullable = false, length = 32)
    @Comment("单据号码")
    private String orderNumber;  //单据号码

    @Column(name = "ORDER_SERIAL_NUMBER", nullable = false)
    @Comment("单据序号")
    private Integer orderSerialNumber;  //单据序号

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PURCHASING_ORGANIZATION_ID", referencedColumnName = "id", nullable = false)
    @Comment("采购组织编码")
    private PartyRole purchasingOrganization;  //采购组织编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SUPPLIER_ID", referencedColumnName = "id", nullable = false)
    @Comment("供应商编码")
    private PartyRole supplier;  //供应商编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "id", nullable = false)
    @Comment("商品编码")
    private Product product;  //商品编码

    @Column(name = "BATCH_CODE")
    @Comment("批次内码")
    private Long batchCode;  //批次内码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PURCHASING_GROUP_ID", referencedColumnName = "id", nullable = false)
    @Comment("采购组编码")
    private PartyRole purchasingGroup;  //采购组编码

    @Column(name = "TYPE_OF_PURCHASE_PROTOCOL", nullable = false)
    @Comment("采购协议属性")
    private Integer typeOfPurchaseProtocol;  //采购协议属性

    @Column(name = "CHANGE_TIME", nullable = false)
    @Comment("变动时间")
    private Date changeTime;  //变动时间

    @Column(name = "CHANGE_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("变动数量")
    private double changeQty = 0.0;  //变动数量

    @Column(name = "BALANCE_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("结存数量")
    private double balanceQty = 0.0;  //结存数量

    @Column(name = "BALANCE_MONEY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("结存金额")
    private double balanceMoney = 0.0;  //结存金额

    @Column(name = "NO_TAX_COST_PRICE", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("无税成本单价")
    private double noTaxCostPrice = 0.0;  //无税成本单价

    @Column(name = "TAX_COST_PRICE", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("含税成本单价")
    private double taxCostPrice = 0.0;  //含税成本单价

    @Column(name = "ORDER_PRICE", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("单据单价")
    private double orderPrice = 0.0;  //单据单价

    @Column(name = "NOTE", nullable = false, length = 256)
    @Comment("备注")
    private String remarks;  //备注

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SALES_ORGANIZATION_ID", referencedColumnName = "id", nullable = false)
    @Comment("销售组织编码")
    private PartyRole salesOrganization;  //销售组织编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SHOP_ID", referencedColumnName = "id", nullable = false)
    @Comment("门店编码")
    private PartyRole shop;  //门店编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_ID", referencedColumnName = "id", nullable = false)
    @Comment("公司编码")
    private PartyRole company;  //公司编码

}
